﻿using IMark.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IMark.UC
{
    public partial class SlideTinTucCtrl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                List<BAI_VIET> ltBaiViet = BaiVietModels.GetAll().Take(5).ToList();
                slideTinTuc.InnerHtml = GenerateBaiViet(ltBaiViet);
            }
        }

        private string GenerateBaiViet(List<BAI_VIET> ltBaiViet)
        {
            StringBuilder str = new StringBuilder();
            if(ltBaiViet!=null)
            {
                for (int i = 0; i < ltBaiViet.Count; i++)
                {
                    if(i==0)
                        str.Append("<div class='blog-entry item active'>");
                    else
                        str.Append("<div class='blog-entry item'>");
                    str.Append("<div class='image'>");
                    str.Append("<a href='DocTin.aspx?ID=" + ltBaiViet[i].ID + "'><span class='blogico'><i class='fa fa-bullhorn fa-fw'></i></span>");
                    str.Append("<img class='ani-image' style='width:570px;height:248px' src='images/blog/" + ltBaiViet[i].Hinh + "' alt='image info'></a>");
                    str.Append("</div>");
                    str.Append("<div class='entry-row'>");
                    str.Append("<div class='date col-xs-12'><span>" + ltBaiViet[i].NgayTao.Day + "</span><span>" + ltBaiViet[i].NgayTao.Month + "/" + ltBaiViet[i].NgayTao.Year + "</span></div>");
                    str.Append("<div class='blog-text'>");
                    str.Append("<a href='DocTin.aspx?ID=" + ltBaiViet[i].ID + "'><div style='height:31px;overflow:hidden;font-size:22px;font-weight:300;text-overflow: ellipsis;white-space: nowrap;' title='" + ltBaiViet[i].TieuDe + "'>" + ltBaiViet[i].TieuDe + "</div></a>");
                    str.Append("<div style='height:35px;overflow:hidden'>" + ltBaiViet[i].NoiDungTomTat + "</div> <span><a href='TinTuc.aspx?IDTacGia="+ltBaiViet[i].NguoiTao+"'>");
                    str.Append("<i class='fa fa-user fa-fw'></i>" + ltBaiViet[i].NGUOI_DUNG.HoTen + "</a>");
                    str.Append("</span>");
                    str.Append("</div>");
                    str.Append("</div>");
                    str.Append("</div>");
                }
            }
            return str.ToString();
        }
    }
}